package Servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class The
 */
@WebServlet("/The")
public class The extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public The() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		response.getWriter().append("Served at: ").append(request.getContextPath());
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
		request.setCharacterEncoding("utf-8");
		response.setCharacterEncoding("utf-8");
		response.setContentType("text/html;charset=utf-8");
		
		String s=request.getParameter("text1");
		String s1=request.getParameter("password");
		String s2=request.getParameter("radio");
		String s3=request.getParameter("checkbox");
		String s4=request.getParameter("select1");
		String s5=request.getParameter("select2");
		String s6=request.getParameter("email");
		String s7=request.getParameter("image");
		String s8=request.getParameter("text2");
		
		System.out.printf(s);
		System.out.printf(s2);
		System.out.printf(s3);
		System.out.printf(s4);
		System.out.printf(s5);
		System.out.printf(s6);
		System.out.printf(s7);
		System.out.printf(s8);
		
	    ServletContext servletcontext=this.getServletContext();
		Integer account=(Integer) servletcontext.getAttribute("account");
		PrintWriter out= response.getWriter();
		
		if(account!=null) {
			servletcontext.setAttribute("account", ++account);
			out.println("访问次数："+account+"次");
		}else {
			servletcontext.setAttribute("account",1);
			out.println("访问次数"+1+"次");
		}
		
		out.close();
	}

}
